<%@page import="interfaces.DALException"%>
<%@page import="java.util.List"%>
<%@page import="dto_objects.*"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>

<% 
String login = "<form action=\"LoginServlet\">"+
		"Username:<br>"+
		"<input type=\"text\" name=\"un\"><br>"+
		"Password:<br>"+
		"<input type=\"text\" name=\"pw\">"+
		"<input type=\"submit\" value=\"log In\">"+
		"&nbsp;"+
		"</form>";
%>

<script type="text/javascript" src="../javascripts/jquery-latest.pack.js"></script>
<script type="text/javascript" src="../javascripts/popup.js"></script>

<jsp:useBean id="func" class="Function.FunctionLIBRARY" scope="session"/>  

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
	<title>Delete Book</title>
	<link rel="stylesheet" type="text/css" href="../NewStyle.css">
</head>
<body>
	<div id=topBox>
			<div id=searchField>
				<form action="../Web/MainPage.jsp">
				<input type="text" name="searchText"> 
				<input type="submit" value="">
				<a id="aSearchButton" href="../Search/aSearch.jsp">Advanced search</a>
				</form>			
			</div>
	
			<div id=login>
				<%out.print(func.getClass().getName());
				if(session.getAttribute("currentSessionUser") == null){
					session.setAttribute("userMENU", null);
					out.print("<a class=myButton href=\"#loginField\" name=\"loginFieldClick\">Login</a>");
				}else{
					out.print("<form action=\"../LoginServlet\">"+
							"<input class=myButton type=\"submit\" value=\"Log Out\" name=\"logout\">"+
							"</form>");
				}
				%>
				
				
			</div>
	</div>
	<div id=main>
		<div id=header>

		</div>
		<div id=content>
			<div id=data>
		
		
					<form method="GET">
					<div class=tabledesign style="float:left;">
	<%

	out.print("<table id=\"tabledesign\">");
	out.print("<tr>");
	out.print("<td>BookID </td>");
	out.print("</tr>");
		out.print("<tr>");
		out.print("<td><input type=\"text\" name=\"BookID\" value=\"\" size=4></td>"); 
		out.print("</tr>");
	out.print("</table>");
	
%>
</div>
<br><input type="submit" name="submit" value="Search"><br><br><br>
<div class=tabledesign style="float:left;">
	<%
	BookDTO book;	
	if (request.getMethod().equals("GET") && request.getParameter("BookID") != null && request.getParameter("submit") != null) {
		if(request.getParameter("submit").equalsIgnoreCase("Search")){
			try{
				book = func.getBookCopyByID(Integer.parseInt(request.getParameter("BookID")));
				out.print("<table id=\"tabledesign\">");
				out.print("<tr>");
				out.print("<td> BookID </td>");
				out.print("<td> ISBN </td>");
				out.print("<td></tr>");
				
				out.print("<tr>");
				
				out.print("<td> "+book.getBookID()+" </td>");
				out.print("<td> "+book.getISBN()+" </td>");
				out.print("<td><input type=\"submit\" name=\"delete\" value=\"Delete\"></td>");
				session.setAttribute("delBook", book);

				out.print("</tr>");
				out.print("</table>");
			}catch(DALException e){
				out.print(e.getLocalizedMessage());
			}catch(NumberFormatException e){
				out.print("Invalid Input");
			}
		}
	}
	if (request.getMethod().equals("GET") && request.getParameter("delete") != null) {
		if(request.getParameter("delete").equalsIgnoreCase("Delete")){
			book = (BookDTO)session.getAttribute("delBook");
			func.deleteBook_Copy(book.getBookID());
			out.print("Deleted!");
		}
	}
	
%>
</div>
</form>
		
		
			</div>
		${userMENU}
		</div>
	</div>

<div id="loginField" class="window">
	<form action="../LoginServlet">
			Username:
			<input type="text" name="un"><br>
			Password:
			<input type="text" name="pw"><br>
			<input type="submit" value="Log In">
		</form>	
		<br>
	<a href="#"class="close" align=right style="color: #333;text-align: right;text-decoration: none;">Close</a>
</div>	
<div id="mask"></div>

</body>
</html>